package com.xinnet.mms.customerManage.dao.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.core.utils.page.PageView;
import com.xinnet.mms.customerManage.dao.CustomerManageDao;
import com.xinnet.mms.entity.Area;
import com.xinnet.mms.entity.CustomMixAudit;
import com.xinnet.mms.entity.Customer;
import com.xinnet.mms.entity.CustomerCare;
import com.xinnet.mms.entity.CustomerRemark;
import com.xinnet.mms.entity.Dept;
import com.xinnet.mms.entity.Emp;
import com.xinnet.mms.entity.EmpCustomRelation;
import com.xinnet.mms.entity.Product;
import com.xinnet.mms.entity.PushHistory;
import com.xinnet.mms.entity.PushResults;

@Repository("customerManageDao")
public class CustomerManageDaoImpl extends BaseDaoImpl<Customer,Long> implements CustomerManageDao{
	
	public List<Customer> getAllCustom(){
		List<Customer> customerList = super.getSqlSession().selectList("customerallot.getAllCustom");
		return customerList;
	}

	
	public void updateCustomer(Customer customer){
		Map<String, String> map = new HashMap<String, String>();
		String cus_id = customer.getCusId();
		map.put("cus_id",cus_id);
		super.getSqlSession().update("customerallot.updateCustomer",customer);
	}
	
	public void updateCustomerProduct(Customer customer){
		Map<String, String> map = new HashMap<String, String>();
		String cus_id = customer.getCusId();
		map.put("cus_id",cus_id);
		super.getSqlSession().update("customerallot.updateCustomerProduct",customer);
	}
	public void  goOpenSea(Customer customer){
		super.getSqlSession().update("customerallot.updateToOpenSea",customer);
	}
	
	public void newRegisterCustomTransfer(String customId){
		Customer customer = new Customer();
		customer.setCusId(customId);
		super.getSqlSession().update("customerallot.updateNewRegisterCustom",customer);
	}
	/**
	 * 批量更新公海客户为服务期客户
	 * @param customIdList
	 */
	public void batchUpateOpenSeaCustom(List<String> customIdList){
		
		super.getSqlSession().update("customerallot.batchUpateOpenSeaCustom",customIdList);
		
	}

	
	@Override
	public void addEmpCustomRelation(EmpCustomRelation empCustomRelation) {
		 
		super.getSqlSession().update("empCustomer.addEmpCustomer",empCustomRelation);
	}

	@Override
	public List<Customer> queryAllCustomerByType(PageView<Customer> pageView, Customer customer) {
		 
		return super.getSqlSession().selectList("customer.queryAllCustomerByType", customer);
	}

	
	@Override
	public void modifyCustomerById(Customer customer) {
		 
		super.getSqlSession().update("customer.modifyCustomerById", customer);
	}

	
	@Override
	public void addCustomer(Customer customer) {
		 
		super.getSqlSession().insert("customer.addCustomer", customer);
	}

	@Override
	public void updateCustomerCareeEmpno(CustomerCare customerCare) {
		 
		super.getSqlSession().update("customerManage.updateCustomerCareeEmpno", customerCare);
	}

	@Override
	public List<Dept> getDeptByProductIds(Dept dept) {
		return super.getSqlSession().selectList("Dept.getDeptByProductIds", dept);
	}
	@Override
	public Customer queryCustomerByPhoneAndEmail(Customer customer) {
		 
		return super.getSqlSession().selectOne("customer.queryCustomerByPhoneAndEmail", customer);
	}
	
	@Override
	public List<Customer> queryCustomerByPhoneOrEmail(Customer customer) {
		 
		return super.getSqlSession().selectList("customer.queryCustomerByPhoneOrEmail", customer);
	}
	
	@Override
	public Customer queryCustomerByPhone(Customer customer) {
		 
		return super.getSqlSession().selectOne("customer.queryCustomerByPhone", customer);
	}
	
	@Override
	public Customer queryCustomerByEmail(Customer customer) {
		 
		return super.getSqlSession().selectOne("customer.queryCustomerByEmail", customer);
	}


	@Override
	public void delCustomerByIds(Customer customer) {
		 
		super.getSqlSession().delete("customer.delCustomerByIds", customer);
	}

	
	public void delCustomByCname(String customName){
		 super.getSqlSession().delete("customerallot.delCustomByCname",customName);
	}
	public void addCustom(Customer customer){
		 super.getSqlSession().insert("customer.addCustomer",customer);
	}

	public List<Customer> getOfServiceCustomerByEmpNoStr(String empNoStr){
		List<Customer> customerList = super.getSqlSession().selectList("customerallot.getOfServiceCustomerByEmpNoStr",empNoStr);
		return customerList;	
	}
	
	public void addCustomMixAudit(CustomMixAudit customMixAudit){
		super.getSqlSession().insert("custommix.addCustomMixAudit",customMixAudit);
	}
	public List<CustomMixAudit> getAllCustomMixAudit(){
		List<CustomMixAudit> customMixAuditList = super.getSqlSession().selectList("custommix.getAllCustomMixAudit");
		return customMixAuditList;
	}
	
	public List<Customer> getOfServiceCustomer(Map<String,Object> param){
		List<Customer> customerList = super.getSqlSession().selectList("customerallot.getOfServiceCustomer",param);
		return customerList;	
	}
	
	public List<CustomMixAudit> getCustomDeployApprovalItems(String deptIdStr,String approvalerId){
		CustomMixAudit customMixAudit = new CustomMixAudit();
		customMixAudit.setDeptIdStr(deptIdStr);
		customMixAudit.setApprovalerId(approvalerId);
		List<CustomMixAudit> customMixAuditList = super.getSqlSession().selectList("custommix.getCustomDeployApprovalItems",customMixAudit);
		return customMixAuditList;
	}
	
	public List<CustomMixAudit> getCustomMixAudit(Map<String,Object> param){
		List<CustomMixAudit> customMixAuditList = super.getSqlSession().selectList("custommix.getCustomMixAudit",param);
		return customMixAuditList;
	}
	
	public Integer getCustomMixAuditCount(Map<String,Object> param){
		return super.getSqlSession().selectOne("custommix.getCustomMixAuditCount",param);
	}
	
	public int updateCustomMixAudit(CustomMixAudit customMixAudit) throws Exception{
		return super.getSqlSession().update("custommix.updateCustomMixAudit",customMixAudit);
	}
	public void updateCustomMixAuditFlagByCustomMixId(String customMixId){
		super.getSqlSession().update("custommix.updateCustomMixAuditFlagByCustomMixId",customMixId);
	}
	
	@Override
	public List<Area> getAreaByDeptId(String deptId) {
		return super.getSqlSession().selectList("customerManage.getAreaByDeptId", deptId);
	}


	@Override
	public List<Customer> queryReportedCustomer(PageView<Customer> pageView,Customer customer) {
		 
		Integer startPage = pageView.getFirstResult();
		customer.setLimitTop(startPage);
		customer.setLimitDown(pageView.getPageSize());
		return getSqlSession().selectList("customer.getReportedCustomer", customer);
	}


	@Override
	public CustomerCare getCustomerCareByCondition(CustomerCare customerCare) {
		 
		return super.getSqlSession().selectOne("customerCare.getCustomerCareByCustomIdAndProductId",customerCare);
	}


	@Override
	public List<Product> getProductByParentId(String parentId) {
		 
		return super.getSqlSession().selectList("product.getProductByParentId", parentId);
	}


	@Override
	public List<CustomerCare> getCustomerCareListByCondition(
			CustomerCare customerCare) {
		 
		return super.getSqlSession().selectList("customerCare.getCustomerCareListByCondition", customerCare);
	}


	@Override
	public List<Product> getNotPushProductByCustomerId(String cusId) {
		 
		return super.getSqlSession().selectList("product.getNotPushProductByCustomerId", cusId);
	}


	@Override
	public List<CustomerRemark> queryCustomerRemark(
			PageView<CustomerRemark> pageView, CustomerRemark customerRemark) {
		 
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("paging", pageView);
		map.put("t", customerRemark);
		return getSqlSession().selectList("customerRemark.queryCustomerRemark", map);
	}

	@Override
	public List<CustomerRemark> queryCustomerRemark(
			CustomerRemark customerRemark) {
		return getSqlSession().selectList("customerRemark.queryCustomerRemarkByCusId", customerRemark);
	}


	@Override
	public void addCustomerRemark(CustomerRemark customerRemark) {
		 
		super.getSqlSession().insert("customerRemark.addCustomerRemark", customerRemark);
	}

	@Override
	public void updatePushHistoryById(PushHistory pushHistory) {
		 
		super.getSqlSession().update("customerManage.updatePushHistoryById",pushHistory);
	}
	
	public List<Customer> getOfServiceCustomerForDeploy(){
		List<Customer> customerList = super.getSqlSession().selectList("customerallot.getOfServiceCustomerForDeploy");
		return customerList;
	}


	@Override
	public List<Customer> getCustomerByIdArray(Customer customer) {
		 
		return super.getSqlSession().selectList("customer.getCustomerByIdArray", customer);
	}


	@Override
	public void modifyCustomerRemarkById(CustomerRemark customerRemark) {
		 
		super.getSqlSession().update("customerRemark.modifyCustomerRemarkById", customerRemark);
	}


	/**删除400客户*/
	@Override
	public void del400Customer(String cusId) {
		this.getSqlSession().delete("customerRemark.delCustomer",cusId);
		this.getSqlSession().delete("customerRemark.delCustomerFromPushHistory",cusId);
	}

	
	/**查询客户是否在客户服务表中有记录*/
	@Override
	public Integer isBuy(String cusId) {
		return (Integer)this.getSqlSession().selectOne("customerRemark.isBuy",cusId);
	}


	@Override
	public List<PushResults> getPushNumber(PushResults pushResults) {
		 
		return super.getSqlSession().selectList("customerManage.getPushNumber", pushResults);
	}


	@Override
	public List<Product> getIntentionProduct(String cusId) {
		  
		return super.getSqlSession().selectList("customerManage.getIntentionProduct", cusId);
	}


	@Override
	public List<Emp> getEmpListByDeptId(String deptId) {
		String id = deptId;
		return super.getSqlSession().selectList("emp.getEmpListByDeptId", id);
	}


	@Override
	public void updateIsRecyclingByCusId(String cusId) {
		 
		super.getSqlSession().update("customerManage.updateIsRecyclingByCusId", cusId);
	}


	@Override
	public PushHistory getPushHistoryById(String pushHistoryId) {
		
		return super.getSqlSession().selectOne("pushHistory.getPushHistoryById", pushHistoryId);
	}
	
	@Override
	public void updateCustomType(Customer customer){
		super.getSqlSession().update("customerallot.updateCustomType", customer);
	}


	@Override
	public Product getProductByProductId(String productId) {
		
		return super.getSqlSession().selectOne("product.getProductByProductId", productId);
	}


	@Override
	public List<Customer> getCustomerByEmpIdAndCustomState(
			PageView<Customer> page, Customer customer) {
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("paging", page);
		map.put("t", customer);
		return getSqlSession().selectList(this.getClassName()+".getCustomerByEmpIdAndCustomState", map);
	}


	@Override
	public List<Product> getAllProduct() {
		
		return super.getSqlSession().selectList("product.getALLProduct");
	}
	
	public List<Customer> getDeployCustomByMap(Map<String,Object> paramMap){
		//Customer customer = new Customer();
		//customer.setDeptno(deptId);
		//customer.setApplyerId(applyerId);
		List<Customer> customerList = super.getSqlSession().selectList("customerallot.getDeployCustomByMap", paramMap);
		return customerList;
	}
	public Integer getDeployCustomCountByMap(Map<String,Object> paramMap){
		Integer count = super.getSqlSession().selectOne("customerallot.getDeployCustomCountByMap", paramMap);
		return count;
	}
	public List<Customer>  getDeployCustomByParam(Map<String, Object> param){
		List<Customer> customerList = super.getSqlSession().selectList("customerallot.getDeployCustomByParam",param);
		return customerList;	
		
	}
	
	public Integer  getDeployCustomCountByParam(Map<String, Object> param){
		Integer count = super.getSqlSession().selectOne("customerallot.getDeployCustomCountByParam",param);
		return count;	
		
	}
	
	public Customer getDeployCustomByCustomMixId(String customMixId){
		Customer customer = super.getSqlSession().selectOne("customerallot.getDeployCustomByCustomMixId",customMixId);
		return customer;
		
	}


	@Override
	public List<EmpCustomRelation> getCustomerByEmpIdAndCustomType(Customer customer) {
		
		return super.getSqlSession().selectList("customer.getCustomerByEmpIdAndCustomType", customer);
	}
	
	public void updateCustomMixAuditStatusByDeptIdStr(String deptIdStr){
		super.getSqlSession().update("custommix.updateCustomMixAuditStatusByDeptIdStr", deptIdStr);
	}


	@Override
	public List<Customer> getAllNotAcceptCustom(Customer customer) {
		return super.getSqlSession().selectList("customer.getAllNotAcceptCustom", customer);
	}
	
	public List<CustomMixAudit>  getCustomMixAuditByEcrIdAndFromEmpId(String ecrId,String fromEmpId){
		CustomMixAudit customMixAudit = new CustomMixAudit();
		customMixAudit.setEcrId(ecrId);
		customMixAudit.setFromEmpId(fromEmpId);
		List<CustomMixAudit>  customMixAuditList = super.getSqlSession().selectList("custommix.getCustomMixAuditByEcrIdAndFromEmpId", customMixAudit);
		return customMixAuditList;
	}


	@Override
	public List<Customer> getTestCustomer(Customer customer) {
		return this.getSqlSession().selectList("customer.getTestCustomer",customer);
	}


	@Override
	public Integer getAcceptNoCustomerCountByCustomType(Customer customer) {
		
		return super.getSqlSession().selectOne("customer.getAcceptNoCustomerCountByCustomType", customer);
	}
	
	@Override
	public Integer getAddShopCartCustomerCount(Customer customer) {
		
		return super.getSqlSession().selectOne("customer.getAddShopCartCustomerCount", customer);
	}


	@Override
	public Integer getVanishSoonCustomerCount(Customer customer) {
		return super.getSqlSession().selectOne("customer.getVanishSoonCustomerCount", customer);
	}

	@Override
	public Integer getShopCartCustomerCount(Customer customer) {
		return super.getSqlSession().selectOne("customer.getShopCartCustomerCount", customer);
	}

	@Override
	public List<Customer> queryShopCartCustomer(Customer customer) {
		return super.getSqlSession().selectList("customer.queryShopCartCustomer", customer);
	}
	
	@Override
	public List<Customer> queryOpenSeeCustomer(PageView<Customer> pageView,
			Customer customer) {
		Integer startPage = pageView.getFirstResult();
		customer.setLimitTop(startPage);
		customer.setLimitDown(pageView.getPageSize());
		return super.getSqlSession().selectList("customer.queryOpenSeeCustomer", customer);
	}


	@Override
	public List<Customer> getCustomerList(PageView<Customer> pageView,
			Customer customer) {
		Integer startPage = pageView.getFirstResult();
		customer.setLimitTop(startPage);
		customer.setLimitDown(pageView.getPageSize());
		return super.getSqlSession().selectList("customer.getCustomerList", customer);
	}
	
	@Override
	public Integer count(Customer customer) {


		return super.getSqlSession().selectOne("customer.count", customer);
	}
	
	@Override
	public List<Customer> getCustomerList(Customer customer) {
		return super.getSqlSession().selectList("customer.getCustomerListNew", customer);
	}
	
	@Override
	public Integer getCustomerCount(Customer customer) {
		return super.getSqlSession().selectOne("customer.getCustomerCountNew", customer);
	}

	public List<CustomMixAudit> getCustomDeployApprovalItemsByMap(Map<String,Object> paramMap){
		return super.getSqlSession().selectList("custommix.getCustomDeployApprovalItemsByMap", paramMap);
		
	}
	
	public Integer getCustomDeployApprovalItemsCountByMap(Map<String,Object> paramMap){
		return super.getSqlSession().selectOne("custommix.getCustomDeployApprovalItemsCountByMap", paramMap);
	}


	@Override
	public Integer getReportedCustomerCount(Customer customer) {
		
		return super.getSqlSession().selectOne("customer.getReportedCustomerCount", customer);
	}


	@Override
	public Integer getOpenSeeCustomerCount(Customer customer) {
		// TODO Auto-generated method stub
		return super.getSqlSession().selectOne("customer.getOpenSeeCustomerCount", customer);
	}


	@Override
	public Integer getAllfitCustomNum(Customer customer) {
		return super.getSqlSession().selectOne("customer.getAllfitCustomNum",customer);
	}
	
	@Override
	public List<Customer> getAllMindCustom(Customer customer) {
		return super.getSqlSession().selectList("customer.getAllMindCustom",customer);
	}


	@Override
	public List<Customer> getAllWaitChargeCustom(Customer customer) {
		return super.getSqlSession().selectList("customer.getAllWaitChargeCustom",customer);
	}


	@Override
	public List<Customer> getAllProtectCustom(Customer customer) {
		return super.getSqlSession().selectList("customer.getAllProtectCustom",customer);
	}


	@Override
	public List<Customer> getAllSecondCustom(Customer customer) {
		return super.getSqlSession().selectList("customer.getAllSecondCustom",customer);
	}


	@Override
	public Customer getCustomById(Customer customer) {
		// TODO Auto-generated method stub
		return super.getSqlSession().selectOne("customer.getCustomById", customer);
	}
}
